<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/welcome' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
      <el-row :gutter="20">
        <el-col :span="9">
          <div class="grid-content bg-purple">
            <el-input clearable placeholder="请输入内容">
              <el-button slot="append" icon="el-icon-search"></el-button>
            </el-input>
          </div>
        </el-col>
      </el-row>
      <el-table
        border
        stripe
        :data="ordersList">
        <el-table-column
          type="index"
          label="#">
        </el-table-column>
        <el-table-column label="订单编号" prop="order_number"></el-table-column>
        <el-table-column label="订单价格" prop="order_price" width="80px"></el-table-column>
        <el-table-column label="是否付款" prop="pay_status" width="80px">
          <template slot-scope="scope">
            <el-tag type="success" v-if="scope.row.pay_status === '1'">已付款</el-tag>
            <el-tag type="danger" v-else>未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="是否发货" prop="is_send" width="80px"></el-table-column>
        <el-table-column label="下单时间" width="160px">
          <template slot-scope="scope">
            {{ scope.row.create_time | dateFormat }}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="180px">
          <template slot="">
            <el-tooltip effect="dark" content="修改" placement="top" :enterable="false">
              <el-button @click="showDialog" size="mini" type="primary" icon="el-icon-edit"></el-button>
            </el-tooltip>
            <el-tooltip effect="dark" content="物流" placement="top" :enterable="false">
              <el-button @click="showWuliu" size="mini" type="success" icon="el-icon-location-information"></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[4, 6, 10, 20]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </el-card>
    <!-- 修改对话框 -->
    <el-dialog
      title="修改地址"
      :visible.sync="dialogVisible"
      width="50%"
      @close="closeDialog">
      <el-form :model="addRessFrom" :rules="addRessFromRules" ref="addRessFromRef" label-width="100px" class="demo-ruleForm">
        <el-form-item label="省市区县" prop="addRess1">
          <el-cascader
            v-model="addRessFrom.addRess1"
            :options="cityData">
          </el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="addRess2">
          <el-input v-model="addRessFrom.addRess2"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 物流信息对话框 -->
    <el-dialog
      title="物流信息"
      :visible.sync="wuliuDialogVisible"
      width="50%">
      <el-timeline :reverse="reverse">
        <el-timeline-item
          v-for="(activity, index) in wuliuData"
          :key="index"
          :timestamp="activity.time">
          {{activity.context}}
        </el-timeline-item>
      </el-timeline>
      <span slot="footer" class="dialog-footer">
        <el-button @click="wuliuDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="wuliuDialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import cityData from './citydata'
export default {
  data() {
    return {
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 10
      },
      total: 0,
      ordersList: [],
      dialogVisible: false,
      addRessFrom: {
        addRess1: [],
        addRess2: ''
      },
      addRessFromRules: {
        addRess1: [
          { required: true, message: '请选择省市区县', trigger: 'blur' }
        ],
        addRess2: [
          { required: true, message: '请输入详细地址', trigger: 'blur' }
        ]
      },
      cityData: cityData,
      wuliuDialogVisible: false,
      wuliuData: [],
      // 时间轴排序
      reverse: false
    }
  },
  created() {
    this.getOrdersList()
  },
  methods: {
    // 获取订单信息列表
    async getOrdersList() {
      const { data: res } = await this.$http.get('orders', { params: this.queryInfo })
      if (res.meta.status !== 200) return this.$message.error(res.meta.msg)
      this.ordersList = res.data.goods
      this.total = res.total
      console.log(this.ordersList)
    },
    handleSizeChange(newSize) {
      this.queryInfo.pagesize = newSize
      this.getOrdersList()
    },
    handleCurrentChange(newPagenum) {
      this.queryInfo.pagenum = newPagenum
      this.getOrdersList()
    },
    showDialog() {
      this.dialogVisible = true
    },
    closeDialog() {
      this.$refs.addRessFromRef.resetFields()
    },
    async showWuliu() {
      this.wuliuDialogVisible = true
      const { data: res } = await this.$http.get('/kuaidi/804909574412544580')
      if (res.meta.status !== 200) return this.$message.error(res.meta.msg)
      this.wuliuData = res.data
      console.log(this.wuliuData)
    }
  }
}
</script>

<style lang="less" scoped>
.el-pagination{
  margin-top: 15px;
}
.el-cascader{
  width: 100% ;
}
</style>
